package com.qujia.coupon.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.qujia.common.utils.DateUtils;
import com.qujia.coupon.domain.CouponCreation;
import com.qujia.coupon.domain.CouponIssue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.qujia.coupon.mapper.CouponIssueRelationMapper;
import com.qujia.coupon.domain.CouponIssueRelation;
import com.qujia.coupon.service.ICouponIssueRelationService;

/**
 * 发放方式，优惠劵信息Service业务层处理
 *
 * @author qujia
 * @date 2021-08-13
 */
@Service
public class CouponIssueRelationServiceImpl implements ICouponIssueRelationService
{
    @Autowired
    private CouponIssueRelationMapper couponIssueRelationMapper;


    /**
     * 查询发放方式，优惠劵信息
     *
     * @param id 发放方式，优惠劵信息ID
     * @return 发放方式，优惠劵信息
     */
    @Override
    public CouponIssueRelation selectCouponIssueRelationById(Long id)
    {
        return couponIssueRelationMapper.selectCouponIssueRelationById(id);
    }

    /**
     * 查询发放方式，优惠劵信息列表
     *
     * @param couponIssueRelation 发放方式，优惠劵信息
     * @return 发放方式，优惠劵信息
     */
    @Override
    public List<CouponIssueRelation> selectCouponIssueRelationList(CouponIssueRelation couponIssueRelation)
    {
        return couponIssueRelationMapper.selectCouponIssueRelationList(couponIssueRelation);
    }

    /**
     * 通过阶梯拟合优惠卷id
     *
     * @param couponIssueRelation 关联关系
     * @return 通过阶梯拟合优惠卷id
     */
    public List<CouponIssueRelation> selectCouponInfos(CouponIssueRelation couponIssueRelation){
        return couponIssueRelationMapper.selectCouponInfos(couponIssueRelation);
    }


    /**
     * 新增发放方式，优惠劵信息
     *
     * @param couponIssueRelation 发放方式，优惠劵信息
     * @return 结果
     */
    @Override
    public int insertCouponIssueRelation(CouponIssueRelation couponIssueRelation)
    {
        couponIssueRelation.setCreateTime(DateUtils.getNowDate());
        return couponIssueRelationMapper.insertCouponIssueRelation(couponIssueRelation);
    }

    /**
     * 修改发放方式，优惠劵信息
     *
     * @param couponIssueRelation 发放方式，优惠劵信息
     * @return 结果
     */
    @Override
    public int updateCouponIssueRelation(CouponIssueRelation couponIssueRelation)
    {
        couponIssueRelation.setUpdateTime(DateUtils.getNowDate());
        return couponIssueRelationMapper.updateCouponIssueRelation(couponIssueRelation);
    }

    /**
     * 批量删除发放方式，优惠劵信息
     *
     * @param ids 需要删除的发放方式，优惠劵信息ID
     * @return 结果
     */
    @Override
    public int deleteCouponIssueRelationByIds(Long[] ids)
    {
        return couponIssueRelationMapper.deleteCouponIssueRelationByIds(ids);
    }

    /**
     * 删除发放方式，优惠劵信息信息
     *
     * @param id 发放方式，优惠劵信息ID
     * @return 结果
     */
    @Override
    public int deleteCouponIssueRelationById(Long id)
    {
        return couponIssueRelationMapper.deleteCouponIssueRelationById(id);
    }

    @Override
    public int deleteCouponIssueRelation(CouponIssueRelation detail) {
        return couponIssueRelationMapper.deleteCouponIssueRelation(detail);
    }

    @Override
    public List<Integer> selectCouponIdList(CouponIssueRelation couponIssueRelation) {
        List<CouponIssueRelation> list = couponIssueRelationMapper.selectCouponIssueRelationList(couponIssueRelation);
        List<Integer> integerList =new ArrayList<>();
        for(CouponIssueRelation relation:list ){
            integerList.add(relation.getCouponId().intValue());
        }
        return integerList;
    }

    @Override
    public List<CouponIssueRelation> selectListByIssueIds(List<String> issueIds) {
        return couponIssueRelationMapper.selectListByIssueIds(issueIds);
    }


}
